/**
 * Project: apollo-base-tools
 * 
 * File Created at 2017年8月16日
 * 
 * Copyright 2015-2016 dx.com Croporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * DongXue software Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with dx.com.
 */
package org.apollo.base.tools.ui;

import java.awt.Color;
import java.awt.Component;
import java.io.File;

import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.plaf.ColorUIResource;
import javax.swing.tree.DefaultTreeCellRenderer;

/**
 * @ClassName: FileTreeCellRenderer
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author wuzhenfang(wzfbj2008@163.com)
 * @date 2017年8月16日 下午7:58:30
 * @version V1.0
 */
public class FileTreeCellRenderer extends DefaultTreeCellRenderer {

	private static final long serialVersionUID = 1L;

	public FileTreeCellRenderer() {
	}

	@Override
	public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
		FileTree fileTree = (FileTree) tree;
		FileTreeNode fileNode = (FileTreeNode) value;
		File file = (File) fileNode.getUserObject();

		JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
		label.setText(fileNode.getFileName());

		label.setIcon(fileNode.getFileIcon());
		label.setOpaque(false);
		if (fileTree.mouseInPath != null && fileTree.mouseInPath.getLastPathComponent().equals(value)) {
			label.setOpaque(true);
			// label.setBackground(new Color(255, 0, 0, 90));
			label.setBackground(Color.gray);
		}
		return label;
	}

	@Override
	public void setBackground(Color bg) {
		if (bg instanceof ColorUIResource) {
			bg = null;
		}
		super.setBackground(bg);
	}
}
